import java.util.Iterator;
import java.util.Stack;

public class MinStack {
     Stack<Integer> s1;
     Stack<Integer> s2;
    public MinStack() {
        s1=new Stack<>();
        s2=new Stack<>();
    }
    
    public void push(int val) {
        s1.push(val);
        if (s2.empty()){
            s2.push(val);
        }else {
            int ret=s2.peek();
            if (val<=ret){
                s2.push(val);
            }
        }
    }
    
    public void pop() {
        if (!s1.empty()){
            int ret2=s1.pop();
            int peeks2=s2.peek();
            if (ret2==peeks2){
                s2.pop();
            }
        }
    }
    
    public int top() {
        if (!s1.empty()){
            return s1.peek();

        }
        return -1;
    }
    
    public int getMin() {
        if (!s2.empty()) {
            return s2.peek();
        }
        return -1;
    }
}